package com.adinnet.admin.contact.service.impl;

import com.adinnet.admin.common.service.CommonService;
import com.adinnet.admin.contact.model.Contact;
import com.adinnet.admin.contact.mapper.ContactMapper;
import com.adinnet.admin.contact.model.vo.ContactResp;
import com.adinnet.admin.contact.service.ContactService;
import com.adinnet.core.JsonResult;
import com.adinnet.core.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 联系我们（意见反馈） 服务实现类
 * </p>
 *
 * @author zYshuai
 * @since 2020-12-17
 */
@Service
public class ContactServiceImpl extends ServiceImpl<ContactMapper, Contact> implements ContactService {

    @Autowired
    private ContactMapper contactMapper;

    @Autowired
    private CommonService commonService;

    @Override
    @Transactional
    public JsonResult updateStatus(Integer id, String remark, HttpServletRequest request) {
        Contact contact = contactMapper.selectById(id);
        if (null == contact) {
            return JsonResult.error("无该记录");
        }
        contact.setRemark(remark);
        contact.setStatus(1);
        contactMapper.updateById(contact);
        commonService.saveOperation(request, "意见处理，ID：" + contact.getId());
        return JsonResult.ok("处理成功!");
    }

    /**
     * @Description: 意见反馈列表
     * @author zYshuai
     * @Date: 2020/12/17 13:33
     * @return: java.util.List<com.adinnet.admin.contact.model.vo.ContactResp>
     */
    @Override
    public PageResult<ContactResp> contactList(Integer page, Integer limit) {
        Page<ContactResp> ipage = new Page<ContactResp>(page, limit);
        List<ContactResp> contactResps = contactMapper.contactList(ipage);
        return new PageResult<>(contactResps, ipage.getTotal());
    }
}
